var xmlHttp;
var map;
var sightspot;
function createXMLHttpRequest()
{
    if(window.ActiveXObject)
    {
        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    else if(window.XMLHttpRequest)
    {
        xmlHttp=new XMLHttpRequest();
    }
}
function handleStateChange()
{
    if(xmlHttp.readyState==4)
    {
        if(xmlHttp.status==200)
        {
            xmlDoc=xmlHttp.responseXML;
            la=xmlDoc.getElementsByTagName("citylongitude")[0].childNodes[0].nodeValue;
            lb=xmlDoc.getElementsByTagName("citylatitude")[0].childNodes[0].nodeValue;


            var myOptions = {
                zoom: 13,
                center: new google.maps.LatLng(la, lb),
                mapTypeId: google.maps.MapTypeId.ROADMAP
            }
            map = new google.maps.Map(document.getElementById("map_canvas"),
                myOptions);

            //cities=[[xmlDoc.getElementsByTagName("sightspotlongitude")[0].childNodes[0].nodeValue,xmlDoc.getElementsByTagName("sightspotlatitude")[0].childNodes[0].nodeValue,xmlDoc.getElementsByTagName("sightspotname")[0].childNodes[0].nodeValue,xmlDoc.getElementsByTagName("sightspotdescription")[0].childNodes[0].nodeValue],[xmlDoc.getElementsByTagName("sightspotlongitude")[1].childNodes[0].nodeValue,xmlDoc.getElementsByTagName("sightspotlatitude")[1].childNodes[0].nodeValue,xmlDoc.getElementsByTagName("sightspotname")[1].childNodes[0].nodeValue,xmlDoc.getElementsByTagName("sightspotdescription")[1].childNodes[0].nodeValue]];
            sightspot=new Array();
            for(var k=0;k<5;k++){
                sightspot[k]=[xmlDoc.getElementsByTagName("sightlongitude")[k].childNodes[0].nodeValue,xmlDoc.getElementsByTagName("sightlatitude")[k].childNodes[0].nodeValue,xmlDoc.getElementsByTagName("sightname")[k].childNodes[0].nodeValue,xmlDoc.getElementsByTagName("sightdescription")[k].childNodes[0].nodeValue];
            }
            var image = 'images/red_s.png';


            for(var i=0;i<sightspot.length;i++){
                var title=""+sightspot[i][2];

                var myLatLng = new google.maps.LatLng(sightspot[i][0], sightspot[i][1]);
                var sightspotMarker = new google.maps.Marker({
                    position: myLatLng,
                    map: map,
                    icon: image,
                    title:title
                });

                attachMessage(sightspotMarker, i);
            }


           hotel=new Array();
           for(var q=0;q<4;q++){
                hotel[q]=[xmlDoc.getElementsByTagName("propertylongitude")[q].childNodes[0].nodeValue,xmlDoc.getElementsByTagName("propertylatitude")[q].childNodes[0].nodeValue,xmlDoc.getElementsByTagName("propertyname")[q].childNodes[0].nodeValue,xmlDoc.getElementsByTagName("propertydescription")[q].childNodes[0].nodeValue];
           }
            var image1='images/yellow_s.png';

            for(var j=0;j<hotel.length;j++){
                var title1=""+hotel[j][2];

                var myLatLng1 = new google.maps.LatLng(hotel[j][0], hotel[j][1]);
                var hotelMarker = new google.maps.Marker({
                    position: myLatLng1,
                    map: map,
                    icon: image1,
                    title:title1
                });

              attachMessage(hotelMarker, j);
            }

        }
    }
}

function attachMessage(marker, number) {
    var contents='<a href="">Post a comment</a><br />'+sightspot[number][3];
    var infowindow = new google.maps.InfoWindow(
    {
        content: contents,
        size: new google.maps.Size(50,50)
    });
    google.maps.event.addListener(marker, 'mouseover', function() {
        infowindow.open(map,marker);


    });

    google.maps.event.addListener(marker, 'click', function() {
        window.location.href=sightspot[number][2]+'.jsp';
    });
}


function initialize() {
    createXMLHttpRequest();
    str=document.getElementById('city').innerHTML;
    var queryString="Florence.do"+"?city="+str;
    xmlHttp.onreadystatechange=handleStateChange;
    xmlHttp.open("GET",queryString,true);
    xmlHttp.send(null);
}


